/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.Expression;

import java.util.Stack;

/**
 *
 * @author WIN7
 */
public class parseEx {
     public static String Infix2(String input) {
    if (input == null)
        return "";
    char[] in = input.toCharArray();
    Stack<Character> stack = new Stack<Character>();
    
    StringBuilder out = new StringBuilder();

    for (int i = 0; i < in.length; i++)
        switch (in[i]) {
        case '&':
        case '|': 
            
                out.append(' ');
            
        case '(':
            
                out.append(in[i]);
           
        case ' ':
                break;
        case ')':          
                while (!stack.empty() && stack.peek() != '(')
                        out.append(' ').append(stack.pop());
                if (!stack.empty())
                        stack.pop();           
            
                break;
        default:
                out.append(in[i]);
                break;
        }
    
    while (!stack.isEmpty())
        out.append(' ').append(stack.pop());

    return out.toString();

}
}
